package com.automannn.atm_back.modules.codeGenerator.controller;


import com.automannn.atm_back.common.api.vo.Result;
import com.automannn.atm_back.modules.codeGenerator.entity.ColumnConfigEntity;
import com.automannn.atm_back.modules.codeGenerator.entity.GlobalConfigEntity;
import com.automannn.atm_back.modules.codeGenerator.service.GlobalConfigEntityService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.api.R;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * (GeneratorGlobalConfig)表控制层
 *
 * @author chenkaihai
 * @since 2020-07-12 16:58:13
 */
@RestController
@RequestMapping("codeGenerator/generatorGlobalConfig")
@Valid
public class GlobalConfigEntityController {
    /**
     * 服务对象
     */
    @Resource
    private GlobalConfigEntityService globalConfigEntityService;

    /**
     * 分页查询所有数据
     */
    @GetMapping("list")
    public Result selectAll(Page<GlobalConfigEntity> page, GlobalConfigEntity globalConfigEntity) {
        Result<IPage<GlobalConfigEntity>> result = new Result<>();
        IPage<GlobalConfigEntity> pageList = globalConfigEntityService.queryAll(page, globalConfigEntity);
        result.setSuccess(true);
        result.setResult(pageList);
        return result;
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public Result selectOne(@PathVariable String id) {
        return Result.ok(globalConfigEntityService.queryOne(id));
    }

    /**
     * 新增数据
     */
    @PostMapping("add")
    public Result insert(@RequestBody GlobalConfigEntity globalConfigEntity) {
        this.globalConfigEntityService.insert(globalConfigEntity);
        return Result.ok("新增成功!");
    }

    /**
     * 修改数据
     */
    @PutMapping("edit")
    public Result update(@RequestBody GlobalConfigEntity globalConfigEntity) {
        this.globalConfigEntityService.update(globalConfigEntity);
        return Result.ok("修改成功!");
    }

    /**
     * 新增数据
     *
     * @param globalConfigEntityList 实体对象
     * @return 新增结果
     */
    @PostMapping("saveOrUpdate")
    public Result saveOrUpdate(@RequestBody List<GlobalConfigEntity> globalConfigEntityList) {
        this.globalConfigEntityService.saveOrUpdate(globalConfigEntityList);
        return Result.ok("保存成功!");
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除结果
     */
    @DeleteMapping("delete")
    public Result delete(String id) {
        this.globalConfigEntityService.deleteById(id);
        return Result.ok("删除成功!");
    }

    /**
     * 删除数据
     *
     * @param ids 主键
     * @return 删除结果
     */
    @DeleteMapping("deleteBatch")
    public Result deleteBatch(String ids) {
        this.globalConfigEntityService.deleteBatchByIds(ids);
        return Result.ok("批量删除成功!");
    }
}
